/*
 * @Author: 邹威鹏(944740645@qq.com)
 * @remarks: 封装了一些简易的工具类
 */

import axios from './axios';
const app = getApp();
var QQMapWX = require('./qqmap-wx-jssdk');

var qqmapsdk;
qqmapsdk = new QQMapWX({
    key: '4XUBZ-3GYKP-LLMDP-VHLZ6-N323T-KFBOZ'
});
//timestamp   时间戳
//option      格式（年月日  就输入YY-MM-DD   时分  就输入 hh-mm）
//功能如下注释   ↓↓↓↓
let formatDate = (fmt, date) => {
    let ret;
    const opt = {
        "Y+": date.getFullYear().toString(), // 年
        "m+": (date.getMonth() + 1).toString(), // 月
        "d+": date.getDate().toString(), // 日
        "H+": date.getHours().toString(), // 时
        "M+": date.getMinutes().toString(), // 分
        "S+": date.getSeconds().toString() // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}
class MapSDK {
    constructor(props) {}
    search(obj) {
        return new Promise((resolve, resject) => {
            qqmapsdk.search({
                keyword: obj.text,
                page_size: obj.number,
                success: (res) => {
                    resolve(res)
                },
                fail: err => {
                    resject(err)
                }
            })
        })

    }
}
class Children {
    constructor(props) {}
    async getMyChildren() {
        // 查询我的小孩数据测试
        return await axios({
            url: '/api/school/student/self',
            data: {
                id: app.globalData.userInfo.id,
                openid: app.globalData.userInfo.openid,
                type: ''
            },
            header: {
                'Authorization': wx.getStorageSync('token')
            }
        })
    }
    async getMyChildrenHealthData(childrenId) {
        // 查询我的小孩健康数据测试
        return await axios({
            url: '/api/student/health/self',
            data: {
                sid: childrenId,
                openid: app.globalData.userInfo.openid,
                type: ''
            },
            header: {
                'Authorization': wx.getStorageSync('token')
            }
        });
    }
}
var Map = new MapSDK();
var children = new Children();
export {
    formatDate,
    Map,
    children
}